package huoye.shops.huoye.operation.presenter;


import android.util.Log;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.mine.activity.WithdrawEndActivity;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IWithdrawView;
import huoye.shops.huoye.operation.model.OrderInfo;
import huoye.shops.huoye.operation.model.PlatformInfo;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IOrderDetailsView;
import huoye.shops.huoye.user.model.User;


/**
 * Created by uesr on 2017/7/19.
 */

public class OrderDetailsPresenter extends BasePresenter<IOrderDetailsView> {


    private OperationService mService;

    //获取订单详情
    public void  getOrderInfo(String orderId){
        mService.getOrderInfo(orderId,new MineBaseJsonRequestCallback<OrderInfo>(OrderInfo.class) {

            @Override
            public void onSuccess(OrderInfo orderInfo) {
                super.onSuccess(orderInfo);
                view.orderDetails(orderInfo);

            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
             //   Log.e("testaaa",msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //商家修改订单状态
    public void setOrderState(String orderId,String action,String sendType){
        mService.setOrderState(orderId,action,sendType,new MineBaseJsonRequestCallback<OrderInfo>(OrderInfo.class) {

            @Override
            public void onSuccess(OrderInfo orderInfo) {
                super.onSuccess(orderInfo);
                view.makeToast("订单操作成功!");
                view.finish();

            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
                //   Log.e("testaaa",msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    //获取平台配送信息
    public void getPlatformInfo(){
        mService.getPlatformInfo(new MineBaseJsonRequestCallback<PlatformInfo>(PlatformInfo.class) {

            @Override
            public void onSuccess(PlatformInfo platformInfo) {
                super.onSuccess(platformInfo);
                view.getPlatformInfoData(platformInfo);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }



    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
